﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Threading;
using Communergy.Common;

namespace CommunergyUploader.Exporters
{
    public class ExportHarness
    {
        IDataExportCommand dataExporter;
        
        Thread exportThread;

        public ExportHarness(IDataExportCommand dataExporter)
        {
            this.dataExporter = dataExporter;

        }

        public void StartExporting()
        {
            exportThread = new Thread(ExportLoop);
            exportThread.Start();
        }

        private void ExportLoop()
        {
            while (true)
            {
                Thread.Sleep(dataExporter.ExportInterval);
                if (dataExporter.LocalCacheRepository != null)
                {
                    dataExporter.ExportData();
                }
            }
        }

        public void StopExporting()
        {
            exportThread.Suspend();
        }
    }
}
